<?php
namespace Mobile\Controller;
use Think\Controller;
class ClassesController extends Controller 
{
	//手机分类显示
    public function index()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);
        //授课城市显示
        $citys = M('city')->where('parent_id=0')->select();
        $this->assign('citys',$citys);

		//获取课程类选择
		$wh = I('get.wh')?I('get.wh'):'';
    	$this->assign('wh',$wh);
    	//课程类选择显示
    	$nianji = M('grade')->where('parent_id=0')->select();
    	$this->assign('nianji',$nianji);

		//获取年级类型选择
		$subject = I('get.subject')?I('get.subject'):'';
    	$this->assign('subject',$subject);
        //年级类型显示
        $gradeid = M('grade')->where(array('grade_name'=>$wh))->getField('gradeid');
        $kecheng = M('grade')->where(array('parent_id'=>$gradeid))->select();
        $this->assign('kecheng',$kecheng);

        //获取科目选择
        $km = I('get.km')?I('get.km'):'';
        $this->assign('km',$km);
        //科目显示
        $kmid = M('grade')->where(array('grade_name'=>$subject))->getField('gradeid');
        $kms = M('grade')->where(array('parent_id'=>$kmid))->select();
        $this->assign('kms',$kms);
        
		// //获取区域选择
		// $area = I('get.area')?I('get.area'):'';
  //   	$this->assign('area',$area);
  //       //区域显示
  //       $cityid = M('city')->where(array('city_name'=>$city))->getField('cityid');
  //       $city_qiyu = M('city')->where(array('parent_id'=>$cityid))->select();
  //       $this->assign('city_qiyu',$city_qiyu);

        //判断是否关键字搜索
        $keyword = I('get.keyword');
        if (!empty($keyword)) {
            //判断是否为数字   
            if (is_numeric($keyword )) {
                $sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t1.id='{$keyword}'";
            }else {
                $sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t1.sfz_name='{$keyword}'"; 
            }

        }else {
            if (!empty($wh) && empty($subject) && empty($km)) {
    			$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t3.class='{$wh}'";
            }elseif (empty($wh) && !empty($subject) && empty($km)) {
            	$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t3.grades='{$subject}'";
            }elseif (empty($wh) && empty($subject) && !empty($km)) {
            	$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t3.subject='{$km}'";
            }elseif (!empty($wh) && !empty($subject) && empty($km)) {
            	$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t3.class='{$wh}' and t3.grades='{$subject}'";	
            }elseif (empty($wh) && !empty($subject) && !empty($km)) {
            	$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t3.grades='{$subject}' and t3.subject='{$km}'";	
            }elseif (!empty($wh) && !empty($subject) && !empty($km)) {
            	$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}' and t3.class='{$wh}' and t3.grades='{$subject}' and t3.subject='{$km}'";	
            }else {
            	$sql = "select t1.id,t1.sfz_name,t1.face,t2.jiaoling,t3.grades,t3.price,t3.subject from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city}'";
            }
        }
        $chaxuns = M()->query($sql);
		$this->assign('chaxuns',$chaxuns);// 赋值数据集

    	
        $this->display();
    }

















}